<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title>APP</title>
		<!--<link rel="stylesheet" type="text/css" href="../css/api.css" />-->
		<link rel="stylesheet" type="text/css" href="../css/aui.css" />
		<!--<link rel="stylesheet" type="text/css" href="../css/common.css" />-->
		<style>
			#contain {
				left: 5px;
				top: 5px;
				margin: 0;
				width: 350px;
				height: 400px;
				position: absolute;
				background-color: black;
				border: 1px solid red;
			}
		</style>
	</head>
	<body>
		<canvas id='contain'></canvas>
		
		
		
		<footer class="aui-nav" id="footer">
			<ul class="aui-bar-tab">
				<li class="active-warning" id="tabbar1" tapmode onclick="Interpolation();switchbtn(0)">
					<span class="aui-iconfont aui-icon-move1"></span>
					<p>
						插值
					</p>
				</li>
				<li id="tabbar2" tapmode onclick="Redraw();switchbtn(1)">
					<span class="aui-iconfont aui-icon-refresh"></span>
					<p>
						重绘
					</p>
				</li>
				<li id="tabbar3" tapmode onclick="Clear();switchbtn(2)">
					<span class="aui-iconfont aui-icon-cut"></span>
					<p>
						清除
					</p>
				</li>
				<li id="tabbar4" tapmode onclick="Save();switchbtn(3)">
					<span class="aui-iconfont aui-icon-upload"></span>
					<p>
						保存
					</p>
				</li>
			</ul>
		</footer>
		<!--		<footer class="homeFooter" id="footer">
		<nav>
		<ul>
		<li tapmode=""  onclick="Interpolation()">
		<span class="am-icon-sm6  am-icon-back">插值</span>
		</li>
		<li apmode=""  onclick="Redraw()">
		<span class="am-icon-sm6  am-icon-back">重绘</span>
		</li>
		<li  tapmode="" onclick="Clear()">
		<span class="am-icon-sm6  am-icon-cut">清除</span>
		</li>
		<li tapmode="" onclick="Clear()">
		<span class="am-icon-sm6  am-icon-picture-o" >保存</span>
		</li>
		</ul>
		</nav>
		</footer>-->
	</body>
	<script type="text/javascript" src="../script/api.js"></script>
	<script type="text/javascript" src="../script/sign.js"></script>
	<script type="text/javascript" src="../script/APICloud-rest-SHA1.js"></script>
	<!--<script type="text/javascript" src="../script/picture.js"></script>-->
	<script type="text/javascript">
		var APPID = "A6996268375072";
		var APPKEY = "DF2513D5-2329-E8B0-7064-A9D8D701D282";
		var sig = null;
		function Interpolation() {
			sig.interpolation(10);
		}

		function Redraw() {
			sig.redraw(10);
		}

		function Clear() {
			sig.clear();
			//sig.drawGrid();
		}

		var userName = "胡华成";
		var userType = "_T_";
		function Save() {
			//console.log(sig.toString());
			var tm = new Date();
			var aYear = tm.getFullYear();
			var aMonth = tm.getMonth() + 1;
			aMonth = (aMonth.toString().length == 1 ? '0' + aMonth : aMonth);
			var aDate = tm.getDate();
			aDate = (aDate.toString().length == 1 ? '0' + aDate : aDate);
			var aHours = tm.getHours();
			aHours = (aHours.toString().length == 1 ? '0' + aHours : aHours);
			var aMin = tm.getMinutes();
			aMin = (aMin.toString().length == 1 ? '0' + aMin : aMin);
			var aSecond = tm.getSeconds();
			aSecond = (aSecond.toString().length == 1 ? '0' + aSecond : aSecond);
			var filename = userName + userType + aYear + aMonth + aDate + aHours + aMin + aSecond + ".txt";
			var path1 = "fs://" + filename;
			
			if(sig.getCount()<=0)
			{
				console.log(sig.getCount());		
				return;
			}			
			api.writeFile({
				path : filename,
				data : sig.toString()
			}, function(ret, err) {
				alert(JSON.stringify(filename));
				var client = new Resource(APPID, APPKEY);
				var model = client.Factory("SignData");
				var bb = client.Factory("SignData");
				bb.save({
					datafile : {
						isFile : true,
						path : "fs://" + filename
						,values : {
										filename : filename
						}
					},
					data : 'dd',
					filename : filename,
					kind : 1,
					userid : "AAA"
				}, function(data, err) {
					alert("file:\t" + JSON.stringify(data));
					alert("file:\t" + JSON.stringify(err));
				});
			});
		}

		//		var client = null;
		//		function InitUpload() {
		//			client = new Resource(APPID, APPKEY);
		//		}
		function switchbtn(index) {
			var footer = $api.byId('footer');
			var footerAct = $api.dom(footer, '.aui-bar-tab li.active-warning');
			$api.removeCls(footerAct, 'active-warning');
			if (index == 0) {
				//$api.text($api.byId('header-title'),'栏目1');
				//$api.addCls($api.byId('tabbar1'), 'active-warning');
			} else if (index == 1) {
				//$api.text($api.byId('header-title'),'栏目2');
				//$api.addCls($api.byId('tabbar2'), 'active-warning');
			} else if (index == 2) {
				//$api.text($api.byId('header-title'),'栏目3');
				//$api.addCls($api.byId('tabbar3'), 'active-warning');
			} else if (index == 3) {
				//$api.text($api.byId('header-title'),'栏目4');
				
				//$api.addCls($api.byId('tabbar4'), 'active-warning');
			}
		}

		apiready = function() {
			var h = api.frameHeight;
			var w = api.frameWidth;
			console.log(w + ',' + h);
			var can = document.getElementById("contain");
			var foot = document.getElementById("footer");
			var pos = getOffset(foot);
			can.style.top = "0px";
			can.style.left = "0px";
			can.style.width = w - 0 + "px";
			can.style.height = h - 0 - pos.h + "px";
			sig = new Sign("contain", 360, 450);
			sig.Init();
			//sig.drawGrid();
			var device = {};
			device.deviceName = api.deviceName;
			device.deviceModel = api.deviceModel;
			device.deviceId = api.deviceId;
			device.systemType = api.systemType;
			device.systemVersion = api.systemVersion;
			sig.setDevice(device);
			//console.log(JSON.stringify(device));
			//console.log(api.systemVerison);
			//contain.width=winW;
			//contain.height=winH-50;
			
			var headHight= api.winHeight-api.frameHeight;
			
			
			window.addEventListener("orientationchange", function() {
				var degree = window.orientation;
				var w = api.winWidth;
				var h = api.winHeight;
				var w1 = api.frameWidth;
				var h1 = api.frameHeight;
				
				if(w>h)
				{
					var t=w;
					w=h;
					h=t;				
				}			
				console.log("degree="+degree+",w="+w+",h="+h);
				
				can.style.width = w - 0 + "px";
				can.style.height = h - 0 - pos.h + "px";				
				sig.Init();				
				sig.degree=degree;												
				if (degree == 0) {
				
					can.style.width = w - 0 + "px";
					can.style.height = h - headHight - pos.h + "px";				
					sig.resize(w,h - headHight - pos.h);
					//sig.redraw(0);
				}
				else
				{
					can.style.width = h - 0 + "px";
					can.style.height = w - headHight - pos.h + "px";				
					sig.resize(h,w - headHight - pos.h);
					//sig.redraw(0);
				}
			}, false);
			
		};
	</script>
</html>